﻿using System.Web.Mvc;
using EBE.COM.Core.Interfaces;
using Newtonsoft.Json;

namespace EBE.COM.Web.Areas.Admin.Controllers
{
  public class SubCategoriesController : Controller
  {
    private readonly IRepository<ICategory> _categoryRepository;
    private readonly IRepository<ISubCategory> _subCategoryRepository;

    public SubCategoriesController(IRepository<ICategory> categoryRepository, IRepository<ISubCategory> subCategoryRepository)
    {
      // inject the UOW instead of the repositories
      _categoryRepository = categoryRepository;
      _subCategoryRepository = subCategoryRepository;
    }

    public ActionResult Index(int id)
    {
      var category = _categoryRepository.FindById(id);
      return View(category);
    }

    public string GetSubCategories(int categoryId)
    {
      var list = _subCategoryRepository.Find(e => e.CategoryId == categoryId); // this doesn't work with my DAL
      return JsonConvert.SerializeObject(list);
    }
  }
}
